package utils

import (
	jsoniter "github.com/json-iterator/go"
	"github.com/json-iterator/go/extra"
)

func init() {
	extra.RegisterFuzzyDecoders()
}

func JsonEncode(v interface{}) ([]byte, error) {
	return jsoniter.Marshal(v)
}

func JsonEncodeToString(v interface{}) (string, error) {
	return jsoniter.MarshalToString(v)
}

func JsonEncodeMust(v interface{}) []byte {
	bytes, _ := jsoniter.Marshal(v)
	return bytes
}

func JsonEncodeToStringMust(v interface{}) string {
	str, _ := jsoniter.MarshalToString(v)
	return str
}

func JsonDecode(bytes []byte, v interface{}) error {
	return jsoniter.Unmarshal(bytes, v)
}

func JsonDecodeString(json string, v interface{}) error {
	return jsoniter.UnmarshalFromString(json, v)
}
